package com.lyn.common.kit;

import java.util.List;

public class SqlKit {
	public static String addWhereParam(String sqlExpect, String field, List<Object> params, Object param) {
		if(sqlExpect.toLowerCase().contains("where")) {
			sqlExpect += " and "+field+"=?";
		}
		else {
			sqlExpect += " where " + field+"=?";
		}
		params.add(param);
		return sqlExpect;
	}
	
	public static String addSetParam(String sqlExpect, String field, List<Object> params, Object param) {
		if(sqlExpect.toLowerCase().contains("set")) {
			sqlExpect += ", "+field+"=?";
		}
		else {
			sqlExpect += " set " + field+"=?";
		}
		params.add(param);
		return sqlExpect;
	}
	
	public static String addWhereIn(String sqlExpect, String field, List<String> ins) {
		if(sqlExpect.toLowerCase().contains("where")) {
			sqlExpect += " and "+field+" in(";
		}
		else {
			sqlExpect += " where " + field+" in(";
		}
		for(String str : ins) {
			sqlExpect += "'" + str + "',";
		}
		sqlExpect = sqlExpect.substring(0, sqlExpect.length()-1);
		sqlExpect += ")";
		return sqlExpect;
	}
	
	public static String addWhereInSplit(String sqlExpect, String field, String ins) {
		if(sqlExpect.toLowerCase().contains("where")) {
			sqlExpect += " and "+field+" in(";
		}
		else {
			sqlExpect += " where " + field+" in(";
		}
		String[] arr = ins.split(",");
		for(String str : arr) {
			sqlExpect += "'" + str + "',";
		}
		sqlExpect = sqlExpect.substring(0, sqlExpect.length()-1);
		sqlExpect += ")";
		return sqlExpect;
	}
}
